import {
	cloneDeep
} from 'lodash'
const state = {
	//订单列表
	orderlistPageList: [],
	orderlistPageCount: null,
	orderlist_sales_list: [],
	orderlistPageForm: {
		name: '',
		page: 1,
		limit: 10,
	},
}
export default {
	state: cloneDeep(state),
	actions: {
		orderlistOnUnload: function() {
			this.orderlistPageForm = cloneDeep(state.orderlistPageForm)
			this.orderlistPageAddress = []
		},
		orderlistOnReachBottom: function() {
			this.orderlistPageForm.page += 1
			this.getorderlistPageList('orderlistOnReachBottom')
		},
		orderlistOnPullDownRefresh: function() {
			this.orderlistPageForm.page = 1
			this.getorderlistPageList('orderlistOnPullDownRefresh')
		},
		getorderlistPageList(form) {
			console.log(form)
			if ((this.orderlistPageCount == this.orderlistPageList.length) && this.orderlistPageForm.page != 1)
				return
			uni.$u.http.get('/order/v1.0/list', {
				params: this.orderlistPageForm,
				custom: {
					showmask: false
				}
			}).then((data) => {
				uni.stopPullDownRefresh()
				if (this.orderlistPageForm.page == 1) {
					uni.pageScrollTo({
						scrollTop: 0,
						duration: 0
					})
					this.orderlistPageList = data.list
				} else {
					this.orderlistPageList = [...this.orderlistPageList, ...data.list]
				}
				this.orderlistPageCount = data.count
				if (data.count == this.orderlistPageList.length) {
					uni.showToast({
						title: '数据已全部加载',
						icon: 'none'
					})
				}
			})
		},
	}
}